IF OBJECT_ID ('dbo.QueryPageList') IS NOT NULL
     DROP PROCEDURE dbo.QueryPageList
     GO

     create procedure dbo.QueryPageList
     (
     @sqlStr varchar(8000),
     @start int,
     @limit int
     )
     as
     DECLARE @dt varchar(10)
     BEGIN

     --# variable to hold the first row number of the page.
     SELECT @dt= substring(convert(varchar, rand()), 3, 10)

     SELECT @sqlStr = stuff(@sqlStr, 1, 7, 'select rownum=identity(12), ')
     SELECT @sqlStr = stuff(@sqlStr, charindex(' FROM ', upper(@sqlStr)), 6 ,' into tempdb..Lining' + @dt + ' from ')
     commit
     execute (@sqlStr)

     --# select the data with the calculated range for first and last row on page.
     select @sqlStr = 'select * from tempdb..Lining' + @dt + ' where rownum > '+convert(varchar, @start)+' and rownum <= '+convert(varchar, (@start+@limit))
     execute (@sqlStr)


     SELECT @sqlStr = 'DROP TABLE tempdb..Lining'+@dt
     EXECUTE (@sqlStr)
     END

     GO